package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import javax.swing.*;
import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Update("update shopping_cart set number = (number+1)  where dish_id = #{dishId}")
    void update(Long dishId);

    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) values(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void add(ShoppingCart shoppingCart);


    @Update("update shopping_cart set number = (number+1)  where setmeal_id = #{setmealId}")
    void update_setm(Long setmealId);

    @Select( "select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    @Select("select * from shopping_cart where dish_id = #{dishId} and dish_flavor=#{dishFlavor}")
   ShoppingCart getDishByDishId(Long dishId,String dishFlavor);

    @Update("update shopping_cart set number = (number-1) where dish_id = #{dishId} and dish_flavor = #{dishFlavor}")
    void sub_one(Long dishId, String dishFlavor);

    @Delete("delete from shopping_cart where dish_id = #{dishId} and dish_flavor=#{dishFlavor}")
    void deleteById(Long dishId ,String dishFlavor);


    @Select("select * from shopping_cart where setmeal_id = #{setmealId}")
    ShoppingCart getStemealBySetmealId(Long setmealId);

    @Update("update shopping_cart set number = (number-1)  where setmeal_id = #{setmealId}")
    void sub_one_setm(Long setmealId);

    @Delete("delete from shopping_cart where setmeal_id = #{id}")
    void deleteById_setm(Long setmealId);

    @Delete("delete from shopping_cart where user_id=#{userId}")
    void clean(Long userId);

    @Select( "select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> getByUserId(Long userId);

    void insert(List<ShoppingCart> shoppingCarts);

}
